<?php
namespace app\common\tool;
class Curd 
{
      public function insert($table= '', $data=[], $scene='', $method="")
      {
           if(request()->$method())
            {
                  $model = model($table);
                  $validate = $model->intValidate();
                  if(!($validate->scene($scene)->check($data)))
                        return returnJson(0, $validate->getError());
                  if($model->save($data))
                  {
                        return returnJson(1, '添加成功'); 
                  }
                  else
                  {
                      return returnJson(0, '数据添加失败，请稍后重试'); 
                  }   
            } 
      }

      public function update($table, $id, $method, $scene, $data)
      {
       
        $model = model($table);
        if(request()->$method())
        {
            $validate = $model->intValidate();
            if(!($info->scene($scene)->check($data)))
                  return returnJson(0, $validate->getError());
            $result = $model->where('id', $id) -> update($data);
            if($result !== false)
            {
              return returnJson(1, '修改成功');
            }
            else
            {
              return returnJson(0, '修改失败，请稍后重试');
            }
        }
      }

	
}